#ifndef		__LOG_H__
#define		__LOG_H__


/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

#define		LOG_LEVEL_NONE		(0)
#define		LOG_LEVEL_INFO		(1)
#define		LOG_LEVEL_WARN		(2)
#define		LOG_LEVEL_ERROR		(3)
#define		LOG_LEVEL_DEBUG		(4)

#define		LOG_MESSAGE_MAXLEN			1024

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief Raw printf log message. 
 * 
 * @param[in] level    - The log level
 * @param[in] location - The location string
 * @param[in] line	   - The file line
 * @param[in] fmt	   - The Pointer to format string, followed by the arguments for conversion.
 */
void log_message(int		  level,
					const char *location,
					int		  line,
					const char *fmt,
					...);

/**
 * @brief Raw printf log message. 
 * 
 * @param[in] level    - The log level
 * @param[in] location - The location string
 * @param[in] line	   - The file line
 * @param[in] prefix   - The pointer to describe
 * @param[in] ptr	   - The pointer to msg
 * @param[in] size	   - The number of msg
 */
void log_hexdecimal(int level,
						const char *location,
						int line,
						const char *prefix,
						const void *ptr,
						int size); 




#define	LOG_MESSAGE(level,fmt,...)									\
	do{																\
		if(LOG_RUN_LEVEL >= level){									\
			log_message(level,__FILE__,__LINE__,fmt,##__VA_ARGS__);	\
		}															\
	}while(0)

#define	LOG_HEXDECIMAL(level,prefix,ptr,len)						\
	do{																\
		if(LOG_RUN_LEVEL >= level){									\
			log_hexdecimal(LOG_LEVEL_INFO,							\
						__FILE__,									\
						__LINE__,									\
						prefix,										\
						ptr,										\
						len);										\
		}															\
	}while(0)
				


#define		LOG_I(...)		LOG_MESSAGE(LOG_LEVEL_INFO,##__VA_ARGS__)	
#define		LOG_W(...)		LOG_MESSAGE(LOG_LEVEL_WARN,##__VA_ARGS__)	
#define		LOG_E(...)		LOG_MESSAGE(LOG_LEVEL_ERROR,##__VA_ARGS__)
#define		LOG_D(...)		LOG_MESSAGE(LOG_LEVEL_DEBUG,##__VA_ARGS__)

#define		LOG_IHEX(prefix,ptr,len)	LOG_HEXDECIMAL(LOG_LEVEL_INFO,prefix,(void *)ptr,len)
#define		LOG_WHEX(prefix,ptr,len)	LOG_HEXDECIMAL(LOG_LEVEL_WARN,prefix,(void *)ptr,len)
#define		LOG_EHEX(prefix,ptr,len)	LOG_HEXDECIMAL(LOG_LEVEL_ERROR,prefix,(void *)ptr,len)
#define		LOG_DHEX(prefix,ptr,len)	LOG_HEXDECIMAL(LOG_LEVEL_DEBUG,prefix,(void *)ptr,len)




 /****************************************************************************/
#ifdef __cplusplus
 }
#endif

#endif

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/

